<% layout('/layouts/default.html', {title: '任务宝活动管理', libs: ['dataGrid']}){ %>
<style>
	.black_overlay{
		display: none;
		position: absolute;
		top: 0%;
		left: 0%;
		width: 100%;
		height: 100%;
		background-color: black;
		z-index:111001;
		-moz-opacity: 0.8;
		opacity:.80;
		filter: alpha(opacity=80);
	}
	.white_content {
		display: none;
		position: absolute;
		top: 10%;
		left: 20%;
		width: 45%;
		height: 90%;
		border: 16px solid lightblue;
		background-color: white;
		z-index:111002;
		overflow: auto;
	}
</style>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text('任务宝活动管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('wxrobot:taskActivity:edit')){ %>
					<a href="${ctx}/wxrobot/taskActivity/form" class="btn btn-default btnTool" title="${text('新增任务宝活动')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${taskActivity}" action="${ctx}/wxrobot/taskActivity/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('活动名称')}：</label>
					<div class="control-inline">
						<#form:input path="name" maxlength="200" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('助力人数')}：</label>
					<div class="control-inline">
						<#form:input path="helps" maxlength="4" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<!--弹出层时背景层DIV-->
<div id="fade" class="black_overlay">
</div>
<div id="QRDiv" class="white_content">
	<div style="text-align: right; cursor: default; height: 40px;" id="move">
		<span style="font-size: 16px;" onclick="CloseQRDiv()">关闭</span>
	</div>
	<img id="qrImg" src="">
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text('活动名称')}', name:'name', index:'a.name', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/wxrobot/taskActivity/form?id='+row.id+'" class="btnList" data-title="${text('编辑任务宝活动')}">'+(val||row.id)+'</a>';
		}},
        {header:'${text('客户列表')}', name:'status', index:'a.status', width:60, align:"center", formatter: function(val, obj, row, act){
                return "<a href='javascript:window.open(\"${ctx}/wxrobot/customer/activityCustomerList?activityId="+row.id+"\")'>查看</a>";
            }},
		{header:'${text('海报图片路径')}', name:'poster', index:'a.poster', width:150, align:"left",formatter:function(val, obj, row, act){
                return "<img src='"+val+"' width='150'; height='150'>";
            }},
		{header:'${text('机器人专属海报')}', name:'robotPoster', index:'a.robot_poster', width:150, align:"left",formatter:function(val, obj, row, act){
                return "<img src='"+val+"' width='150'; height='170'><br/><a href='"+val+"'>下载</a>";
            }},
		{header:'${text('助力人数')}', name:'helps', index:'a.helps', width:150, align:"center"},
		{header:'${text('创建时间')}', name:'createDate', index:'a.create_date', width:150, align:"center"},
		{header:'${text('状态')}', name:'status', index:'a.status', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('robot_activity_status')}, val, '${text('未知')}', true);
		}},
		{header:'${text('操作')}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			//处于草稿状态的活动(发布，删除)
			if(row.status == '4'){
				actions.push('<a href="${ctx}/wxrobot/taskActivity/enable?id='+row.id+'" class="btnList" title="${text('发布活动')}" data-confirm="${text('确认要发布该活动吗？')}"><i class="glyphicon glyphicon-ok-sign"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/wxrobot/taskActivity/delete?id='+row.id+'" class="btnList" title="${text('删除活动')}" data-confirm="${text('确认要删除该活动吗？')}"><i class="glyphicon glyphicon-remove-sign"></i></a>&nbsp;');
				//运行中的活动(停用)
			}else if(row.status == '5'){
				actions.push('<a href="${ctx}/wxrobot/taskActivity/disable?id='+row.id+'" class="btnList" class="btn btn-primary" title="${text('停用活动')}" data-confirm="${text('确认要停用该活动吗？')}"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
				//处于离线状态的活动（发布，删除）
			}else if(row.status == '6'){
				actions.push('<a href="${ctx}/wxrobot/taskActivity/enable?id='+row.id+'" class="btnList" title="${text('发布活动')}" data-confirm="${text('确认要发布该活动吗？')}"><i class="glyphicon glyphicon-ok-sign"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/wxrobot/taskActivity/delete?id='+row.id+'" class="btnList" title="${text('删除活动')}" data-confirm="${text('确认要删除该活动吗？')}"><i class="glyphicon glyphicon-remove-sign"></i></a>&nbsp;');
			}
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

//弹出隐藏层
function ShowQRDiv(imgpath) {
    $("#qrImg").attr("src", "/" + imgpath);
    document.getElementById("QRDiv").style.display = 'block';
    document.getElementById("fade").style.display = 'block';
    var bgdiv = document.getElementById("fade");
    bgdiv.style.width = document.body.scrollWidth;
    $("#fade").height($(document).height());
}
//关闭弹出层
function CloseQRDiv()
{
    document.getElementById("QRDiv").style.display='none';
    document.getElementById("fade").style.display='none';
};

function getHostUrl() {
    var host = window.location.host;
    //获取主机地址之后的目录，如： test/test/test.htm
    //var pathName = window.document.location.pathname;
    //var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    //var rootPath = host + projectName;
    return host;
}


var stest = function () {

    // 初始化一个 WebSocket 对象
    var ws = new WebSocket("ws://" + getHostUrl() + "/qrCodeHandler");

    // 建立 web socket 连接成功触发事件
    ws.onopen = function () {
        // 使用 send() 方法发送数据
        //  ws.send("发送数据");
    };

    // 接收服务端数据时触发事件
    ws.onmessage = function (evt) {
        var received_msg = evt.data;
        if (received_msg == "startSuccess") {
            CloseQRDiv();
        } else {
            ShowQRDiv(received_msg);
            $("#page-loading", parent.document).hide();
        }
    };

    // 断开 web socket 连接成功触发事件
    ws.onclose = function () {
        // alert("连接已关闭...");
    };
}
stest();
</script>